package com.lovo.csc.controller;


import com.lovo.csc.dto.PromotionDto;
import com.lovo.csc.entity.Promotioninfo;
import com.lovo.csc.service.IPromotioninfoService;
import com.lovo.sscsys.dto.SellKillGoodsDto;
import com.lovo.util.MQUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-07-13
 */
@RestController
@RequestMapping("/promotioninfo")
@Api(tags = "促销审核控制层--舒得强")
public class PromotioninfoController {
    @Autowired
    IPromotioninfoService promotioninfoService;
    @Autowired
    RabbitTemplate rabbitTemplate;
    @GetMapping("findAll")
    @ApiOperation(value = "查询促销商品")
    public List<Promotioninfo> findAll(){
        return promotioninfoService.list();
    }
    @PostMapping("promotionInfo")
    @ApiOperation(value = "返回促销审核信息")
    public boolean promotionInfo(PromotionDto promotionDto){
        if (promotionDto != null){
            rabbitTemplate.convertAndSend(MQUtil.PromotionDirectExchange,MQUtil.PromotionInfoKey,promotionDto);
        }
        return true;
    }
    @PostMapping("carePromotionInfo")
    @ApiOperation(value = "返回取消促销审核信息")
    public boolean carePromotionInfo(PromotionDto promotionDto){
        if (promotionDto != null){
            rabbitTemplate.convertAndSend(MQUtil.PromotionDirectExchange,MQUtil.PromotionKey,promotionDto);
        }
        return true;
    }
    @PutMapping("updateState/{PromotioninfoId}/{state}")
    @ApiOperation(value = "修改促销状态")
    public boolean updateState(@PathVariable("PromotioninfoId") int PromotioninfoId,@PathVariable("state") String state){
        promotioninfoService.updateState(PromotioninfoId,state);
        return true;
    }
}
